<?php

class DeletePetAction extends CAction
{
	public function run()
	{
		$pet=Pet::loadPet($_POST['id']);
		if($pet===null)
			throw new CHttpException(404,'cannot find pet['.$id.']');
		$user=&$this->getController()->getUser();
		if($user===null)
			throw new CHttpException(500,'cannot find user['.Yii::app()->user->name.']');
		if($user->name!=$pet->userName)
			throw new CHttpException(401, "user[$user->name] doesn't equal petUserName[$pet->userName] petid=$pet->id");

		if($user->petNum==1)
			$this->getController()->renderPartial('DeletePet',array('result'=>'您不能删除您的所有宠物'));
		else {
			$user->deletePet($pet);
			$this->getController()->renderPartial('DeletePet',array('result'=>'删除成功'));
		}
	}
}

?>
